/*
 *
 *    Copyright (c) 2022 Project CHIP Authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

// THIS FILE IS GENERATED BY ZAP
// This file is generated from clusters-Commands.ipp.zapt

#include <clusters/Thermostat/Commands.h>

#include <app/data-model/Decode.h>
#include <app/data-model/StructDecodeIterator.h>
#include <app/data-model/WrappedStructEncoder.h>

namespace chip {
namespace app {
namespace Clusters {
namespace Thermostat {
namespace Commands {
namespace SetpointRaiseLower {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kMode), mode);
    encoder.Encode(to_underlying(Fields::kAmount), amount);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kMode))
        {
            err = DataModel::Decode(reader, mode);
        }
        else if (__context_tag == to_underlying(Fields::kAmount))
        {
            err = DataModel::Decode(reader, amount);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace SetpointRaiseLower.
namespace GetWeeklyScheduleResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNumberOfTransitionsForSequence), numberOfTransitionsForSequence);
    encoder.Encode(to_underlying(Fields::kDayOfWeekForSequence), dayOfWeekForSequence);
    encoder.Encode(to_underlying(Fields::kModeForSequence), modeForSequence);
    encoder.Encode(to_underlying(Fields::kTransitions), transitions);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNumberOfTransitionsForSequence))
        {
            err = DataModel::Decode(reader, numberOfTransitionsForSequence);
        }
        else if (__context_tag == to_underlying(Fields::kDayOfWeekForSequence))
        {
            err = DataModel::Decode(reader, dayOfWeekForSequence);
        }
        else if (__context_tag == to_underlying(Fields::kModeForSequence))
        {
            err = DataModel::Decode(reader, modeForSequence);
        }
        else if (__context_tag == to_underlying(Fields::kTransitions))
        {
            err = DataModel::Decode(reader, transitions);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace GetWeeklyScheduleResponse.
namespace SetWeeklySchedule {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNumberOfTransitionsForSequence), numberOfTransitionsForSequence);
    encoder.Encode(to_underlying(Fields::kDayOfWeekForSequence), dayOfWeekForSequence);
    encoder.Encode(to_underlying(Fields::kModeForSequence), modeForSequence);
    encoder.Encode(to_underlying(Fields::kTransitions), transitions);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNumberOfTransitionsForSequence))
        {
            err = DataModel::Decode(reader, numberOfTransitionsForSequence);
        }
        else if (__context_tag == to_underlying(Fields::kDayOfWeekForSequence))
        {
            err = DataModel::Decode(reader, dayOfWeekForSequence);
        }
        else if (__context_tag == to_underlying(Fields::kModeForSequence))
        {
            err = DataModel::Decode(reader, modeForSequence);
        }
        else if (__context_tag == to_underlying(Fields::kTransitions))
        {
            err = DataModel::Decode(reader, transitions);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace SetWeeklySchedule.
namespace GetWeeklySchedule {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kDaysToReturn), daysToReturn);
    encoder.Encode(to_underlying(Fields::kModeToReturn), modeToReturn);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kDaysToReturn))
        {
            err = DataModel::Decode(reader, daysToReturn);
        }
        else if (__context_tag == to_underlying(Fields::kModeToReturn))
        {
            err = DataModel::Decode(reader, modeToReturn);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace GetWeeklySchedule.
namespace AddThermostatSuggestionResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kUniqueID), uniqueID);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kUniqueID))
        {
            err = DataModel::Decode(reader, uniqueID);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace AddThermostatSuggestionResponse.
namespace ClearWeeklySchedule {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        ReturnErrorOnFailure(err);
    }
}
} // namespace ClearWeeklySchedule.
namespace SetActiveScheduleRequest {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kScheduleHandle), scheduleHandle);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kScheduleHandle))
        {
            err = DataModel::Decode(reader, scheduleHandle);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace SetActiveScheduleRequest.
namespace SetActivePresetRequest {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kPresetHandle), presetHandle);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kPresetHandle))
        {
            err = DataModel::Decode(reader, presetHandle);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace SetActivePresetRequest.
namespace AddThermostatSuggestion {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kPresetHandle), presetHandle);
    encoder.Encode(to_underlying(Fields::kEffectiveTime), effectiveTime);
    encoder.Encode(to_underlying(Fields::kExpirationInMinutes), expirationInMinutes);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kPresetHandle))
        {
            err = DataModel::Decode(reader, presetHandle);
        }
        else if (__context_tag == to_underlying(Fields::kEffectiveTime))
        {
            err = DataModel::Decode(reader, effectiveTime);
        }
        else if (__context_tag == to_underlying(Fields::kExpirationInMinutes))
        {
            err = DataModel::Decode(reader, expirationInMinutes);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace AddThermostatSuggestion.
namespace RemoveThermostatSuggestion {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kUniqueID), uniqueID);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kUniqueID))
        {
            err = DataModel::Decode(reader, uniqueID);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace RemoveThermostatSuggestion.
namespace AtomicResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kStatusCode), statusCode);
    encoder.Encode(to_underlying(Fields::kAttributeStatus), attributeStatus);
    encoder.Encode(to_underlying(Fields::kTimeout), timeout);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kStatusCode))
        {
            err = DataModel::Decode(reader, statusCode);
        }
        else if (__context_tag == to_underlying(Fields::kAttributeStatus))
        {
            err = DataModel::Decode(reader, attributeStatus);
        }
        else if (__context_tag == to_underlying(Fields::kTimeout))
        {
            err = DataModel::Decode(reader, timeout);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace AtomicResponse.
namespace AtomicRequest {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kRequestType), requestType);
    encoder.Encode(to_underlying(Fields::kAttributeRequests), attributeRequests);
    encoder.Encode(to_underlying(Fields::kTimeout), timeout);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kRequestType))
        {
            err = DataModel::Decode(reader, requestType);
        }
        else if (__context_tag == to_underlying(Fields::kAttributeRequests))
        {
            err = DataModel::Decode(reader, attributeRequests);
        }
        else if (__context_tag == to_underlying(Fields::kTimeout))
        {
            err = DataModel::Decode(reader, timeout);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace AtomicRequest.
} // namespace Commands
} // namespace Thermostat
} // namespace Clusters
} // namespace app
} // namespace chip
